//实时获取、设置页面宽度，
function bdoySizeRander(){
  // 获取当前屏幕body页面宽高
  var screenWidth = document.body.clientWidth;
  var screenHight = document.body.clientHeight;


  //左边导航条的高
  $('.wf-left-box').height(screenHight)
  // console.log(navWidth)
  // //设置导航栏的高度为 100%
  // var widtha
  // var navWidth = $('.wf-left-box').width()

  // widtha = screenWidth - navWidth;
  // $('.wf-right-box').width(widtha)


  //设置页面高度为100%
  var badyHeight;
  window.onload = function () {
    changeDivHeight();
  }
  //当浏览器窗口大小改变时，设置显示内容的高度  
  window.onresize = function () {
    changeDivHeight();
  }
  function changeDivHeight() {
    var h = document.documentElement.clientHeight;//获取页面可见高度  
    badyHeight = h;

    document.getElementById("framediv").style.height = h + "px";
    console.log(badyHeight);
    $('.wf-right-button').height(badyHeight - 90 + 'px')
  }


}

//获取当前时间，处理显示的参数
function nowTime(){
  let date = new Date();
  // console.log(date);
  let y = date.getFullYear();
  let m = date.getMonth() + 1;
  let d = date.getDate();
  let week = date.getDay();
  let h = date.getHours();
  let mm = date.getMinutes();
  let s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (h < 10) {
    h = '0' + h;
  }
  if (mm < 10) {
    mm = '0' + mm;
  }
  if (s < 10) {
    s = '0' + s;
  }
  

  switch (week) {
    case 1:
      week = '一'
      break;
    case 2:
      week = '二';
      break;
    case 3:
      week = '三';
      break;
    case 4:
      week = '四';
      break;
    case 5:
      week = '五';
      break;
    case 6:
      week = '六';
      break;
    case 0:
      week = '日';
      break;
  }
  return (y + '/' + m + '/' + d + " " + '星期' + week + ' ' +  h + ':' + mm + ':' + s) 
}



function navRender() {
  //判断当前登录用户的管理权限
  for (var i = 0; i < administrativeAuthority.length; i++) {
    switch (administrativeAuthority[i]) {
      case 'teacher':
        teacherRander();
        continue;
      case 'student':
        studentRander();
        continue;
      case 'course':
        courseRander();
        continue;
      case 'books':
        booksRander();
        continue;
      case 'department':
        departmentRander();
        continue;
      case 'administrator':
        administratorRander();
        continue;
      case 'application':
        applicationRander();
        continue;
    }
  }
}

//将用户的管理权限分离出来，变成数组
function queryAuthority() {
  if (userInfo.is_teacher == 1) {
    administrativeAuthority.push('teacher')
  }
  if (userInfo.is_student == 1) {
    administrativeAuthority.push('student')
  }
  if (userInfo.is_course == 1) {
    administrativeAuthority.push('course')
  }
  if (userInfo.is_books == 1) {
    administrativeAuthority.push('books')
  }
  if (userInfo.is_department == 1) {
    administrativeAuthority.push('department')
  }
  if (userInfo.is_administrator == 1) {
    administrativeAuthority.push('administrator')
  }
  if (userInfo.is_application == 1) {
    administrativeAuthority.push('application')
  }
  console.log(administrativeAuthority)
  //导航栏渲染
  navRender();
}

//导航栏页面渲染
//教师
function teacherRander() {
  var teacherLi = `<li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-jiaoshiguanli"></span><span class="a-menu">教师管理</span></a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div>
            <a href="./xzh_pages/teacherPage.html" target="myiframe">教师列表</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="./xzh_pages/teacherAdd.html" target="myiframe">新增教师</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="./xzh_pages/teacherIntroduce.html" target="myiframe">教师介绍</a>
          </dd>
        </dl>
      </li>`;
  $('.wf-nav').append(teacherLi)
}
//学生
function studentRander() {
  var studentLi = `<li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-yonghuguanli"></span><span class="a-menu">学生管理</span></a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="ly_pages/student_list.html" target="myiframe">所有学生</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="ly_pages/student_add.html" target="myiframe">新增学生</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="ly_pages/student_details.html" target="myiframe">学生详情</a>
          </dd>
        </dl>
      </li>`
  $('.wf-nav').append(studentLi)
}
//课程
function courseRander() {
  var courseLi = `<li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-zhaokecheng"></span><span class="a-menu">课程管理</span></a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="lxm_pages/all_course.html" target="myiframe">课程列表</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="lxm_pages/add_course.html" target="myiframe">新增课程</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="lxm_pages/introduction_course.html" target="myiframe">课程介绍</a>
          </dd>
        </dl>
      </li>`

  $('.wf-nav').append(courseLi)
}
//图书
function booksRander() {
  var booksLi = `<li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-tushuguan"></span><span class="a-menu">图书管理</span></a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="dxm-pages/dxm-index.html" target="myiframe">所有图书</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="dxm-pages/addbook.html" target="myiframe">新增图书</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="/dxm-pages/describe.html" target="myiframe">图书介绍</a>
          </dd>
        </dl>
      </li>`
  $('.wf-nav').append(booksLi)
}
//部门
function departmentRander() {
  var departmentLi = ` <li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-wangluoxitong"></span><span  class="a-menu">部门管理</a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="flf_pages/Department_list.html" target="myiframe">部门管理</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="flf_pages/new_Department.html" target="myiframe">新增部门</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="flf_pages/Departments.html" target="myiframe">部门介绍</a>
          </dd>
        </dl>
      </li>`
  $('.wf-nav').append(departmentLi)
}
//管理员
function administratorRander() {
  var administratorLi = `<li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-yonghushezhi"></span><span class="a-menu">管理员管理</span></a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="lzx_pages/lzx-list.html" target="myiframe">管理员列表</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="lzx_pages/lzx-guanliyuan.html" target="myiframe">新增管理员</a>
          </dd>
        </dl>
      </li>`
  $('.wf-nav').append(administratorLi)
}
//应用管理
function applicationRander() {
  var applicationLi = `<li class="layui-nav-item ">
        <a href="javascript:;"><span class="iconfont icon-icon_yingyongguanli"></span><span class="a-menu">应用管理</span></a>
        <dl class="layui-nav-child wf-nav-list">
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="javascript:;" target="myiframe">小部件</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="javascript:;" target="myiframe">电子邮件</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div><a href="javascript:;" target="myiframe">日历</a>
          </dd>
          <dd>
            <div class='wf-jieidan'>
              <div class='wf-jieidan-circle'></div>
            </div>
            <a href="javascript:;" target="myiframe">直播</a>
          </dd>
        </dl>
      </li>`
  $('.wf-nav').append(applicationLi)
}


//获取当前登录用户的所有信息
function gettingInformation() {
  $.ajax({
    method: 'GET',
    url: '/users/getInformation',
    data: {
      loginId: logId,
    }
  })
    .done(function (res) {
      console.log('请求成功：', res);
      userInfo = res.data;
      console.log(userInfo)

      queryAuthority()
    })
    .fail(function (err) {
      console.log('请求失败：', err);
    });
}

